#!/usr/bin/env bash

set -e

symbol_file=$(mktemp)
wasm_files=$(find target -maxdepth 2 -name 'tree-sitter-*.wasm')

while read -r wasm_file; do
  wasm-objdump                   \
    --details "$wasm_file"    \
    --section Import             \
    | egrep -o '<\w+>'           \
    | tr -d '<>'                 \
    >> $symbol_file
done <<< "$wasm_files"

sort -u -o $symbol_file $symbol_file
cat $symbol_file
